package com.weixin.service.impl;

import java.sql.SQLException;
import java.util.List;

import com.weixin.dao.StudentDao;
import com.weixin.dao.impl.StudentImpl;
import com.weixin.entity.Student;
import com.weixin.entity.User;
import com.weixin.service.StudentService;

public class impl implements StudentService {
     StudentDao dao=new StudentImpl();
     
	@Override
	public List<Student> findAll() throws SQLException {
		return dao.selsctAll();
	}

	@Override
	public Student findByid(int s_id) throws SQLException {
		return dao.selectByid(s_id);
	}

	@Override
	public boolean removeByid(int u_id) throws SQLException {
		if (dao.deleteByRole(u_id)) {
			return dao.deleteByid(u_id);
		}return false;
	}

	@Override
	public boolean add(Student student) throws SQLException {
		if (dao.selsctByName(student.getName())!=null) {
			dao.insert(student);
		}
		return false;
	}

	@Override
	public boolean update(Student student) throws SQLException {
		return dao.update(student);
	}

	@Override
	public List<User> ListAllBypage(String role, int pageNum, int pageSize) throws SQLException {
		return dao.getAllBypage(role, pageNum, pageSize);
	}

	@Override
	public int getTotal(String role) throws SQLException {
		return dao.getTotal(role);
	}

	@Override
	public User select(String name, String password) throws SQLException {
		return dao.select(name, password);
	}

	@Override
	public List<User> ListByrole(String role) throws SQLException {
		return dao.ListByrole(role);
	}
	public boolean deleteByAll(List<String> u_ids) throws SQLException{
		if (dao.deleteByRoleAll(u_ids)) {
			return dao.deleteByAll(u_ids);
		}
		return false;
	}

	@Override
	public List<User> selectAllSearch(String role, String search, int pageNum, int pageSize) throws SQLException {
		return dao.selectSearch(role, search, pageNum, pageSize);
	}

	@Override
	public int selectAllTotalSearch(String role, String search) throws SQLException {
		return dao.selectTotalSearch(role, search);
	}
}
